package gold.digger;

import gold.utils.InputUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1894 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int chalkReplacer(int[] chalk, int k) {
            int sum = 0;
            for (int i = 0; i < chalk.length; i++) {
                sum += chalk[i];
                if (sum > k) return i;
            }

            k %= sum;
            for (int i = 0; i < chalk.length; i++) {
                if (k < chalk[i]) return i;
                k -= chalk[i];
            }

            return 0;
        }
    }

    public void run() {
        Solution solution = new Solution();
//        int[] arr = InputUtil.toIntegerArray("[3,4,1,2]");
        int[] arr = InputUtil.readLongArrayFromFile("input.txt");
        System.out.println(solution.chalkReplacer(arr, 539095482));
    }

    public static void main(String[] args) throws Exception {
        LC1894 an = new LC1894();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
